*Data*
clear all
clear mata

*Set working directory
*Load Data*
use "FinalDataset.dta", clear
cd ""

***************************************************************************************************
***************************************************************************************************
*****************Figure 1: Equality and Exclusionary Alliances Vary Across Countries***************
***************************************************************************************************
***************************************************************************************************

*Panel A: Equality*
cibar equality if proposer==1, ///
over1(iso3E) ///
graphopts(xtitle("Country") ytitle("Average Proposal Equality")  title("a) Equality") ylab(69 " " 70 "70" 75 "75" 80 "80" 85 "85" 90 "90",angle(0) noticks) graphregion(fcolor(white) icolor(white) lcolor (white) ilcolor(white) ifcolor(white)) legend(off) xlab(1 "AUS" 2 "AUT" 3 "CHN" 4.1 "COL" 5.1 "DEU" 6.2 "DNK" 7.2 "EGY" 8.2 "ESP" 9.2 "GBR" 10.3 "GTM" 11.3 "JPN" 12.3 "KEN" 13.4 "URY" 14.4 "USA",angle(vertical) noticks)) barlabel(off) blf(%9.2f) blsize(tiny) blposition(1) barcolor(edkblue emidblue eltblue emerald erose ebblue eltgreen stone navy maroon brown lavender teal cranberry ) bargap(3) ciopts(lcolor(grey%50)) 
graph save "Gini_avg.gph", replace

*Panel B: MWC*
cibar MWC if proposer==1, ///
over1(iso3E) ///
graphopts(xtitle("Country") ytitle("Fraction of Exclusionary Alliances") title("b) Exclusionary Alliances")  ylab(.15 " " .2 ".2" .3 ".3" .4 ".4" .5 ".5" .6 ".6" .7 ".7" .8 ".8",angle(0) noticks) graphregion(fcolor(white) icolor(white) lcolor (white) ilcolor(white) ifcolor(white)) legend(off) xlab(1 "AUS" 2 "AUT" 3 "CHN" 4.1 "COL" 5.1 "DEU" 6.2 "DNK" 7.2 "EGY" 8.2 "ESP" 9.2 "GBR" 10.3 "GTM" 11.3 "JPN" 12.3 "KEN" 13.4 "URY" 14.4 "USA",angle(vertical) noticks)) barlabel(off) blf(%9.2f) blsize(tiny) blposition(1) barcolor(edkblue emidblue eltblue emerald erose ebblue eltgreen stone navy maroon brown lavender teal cranberry ) bargap(3) ciopts(lcolor(grey%50)) 
graph save "MWC_avg.gph", replace

graph combine "Gini_avg.gph" "MWC_avg.gph", scheme(s1color) imargin(-3 -3 -4 -4) 
graph export "Fig1.pdf", as(pdf) replace

***************************************************************************************************
***************************************************************************************************
************Table 1: Individual-Level Predictors of Equality and Exclusionary Alliances************
***************************************************************************************************
***************************************************************************************************

est clear
foreach var in equality MWC { 
regress `var' Gender if proposer==1, cl(UniqueID)
estadd scalar n = e(N)
estimates store `var'_col1
estadd local SE "Indiv"
estadd local FE " "
estadd local Proposals "All"

regress `var' CRT_dich if proposer==1, cl(UniqueID)
estadd scalar n = e(N)
estimates store `var'_col2
estadd local SE "Indiv"
estadd local FE " "
estadd local Proposals "All"

regress `var' PolAttIndex if proposer==1, cl(UniqueID)
estadd scalar n = e(N)
estimates store `var'_col3
estadd local SE "Indiv"
estadd local FE " "
estadd local Proposals "All"

regress `var' Gender CRT_dich PolAttIndex if proposer==1, cl(UniqueID)
estadd scalar n = e(N)
estimates store `var'_col4
estadd local SE "Indiv"
estadd local FE " "
estadd local Proposals "All"

areg `var' Gender CRT_dich PolAttIndex if proposer==1, cl(UniqueID) absorb(Country)
estadd scalar n = e(N)
estimates store `var'_col5
estadd local SE "Indiv"
estadd local FE "Country"
estadd local Proposals "All"

}

*Panel A: Equality*
esttab equality_col1 equality_col2 equality_col3 equality_col4 equality_col5 using "Table1A.tex", replace  ///
cells(b(fmt(%9.2f) star) se(par fmt(%9.2f))) style(tex) ///
stats(n SE FE Proposals, labels("N" "Clustering" "FE" "Proposals") ///
fmt(%9.0f %9.0f %9.0f %9.0f)) ///
starlevels(* .05 ** .01 *** .001) ///
keep(Gender CRT_dich PolAttIndex) /// 
order(Gender CRT_dich PolAttIndex) /// 
varlabels (Gender "Female" CRT_dich "High CRT Score" PolAttIndex "Political Attitudes Index \\ (Right $\rightarrow$ Left)" ) ///
mlabels(none) collabels(none)	

*Panel B: MWC*
esttab MWC_col1 MWC_col2 MWC_col3 MWC_col4 MWC_col5 using "Table1B.tex", replace  ///
cells(b(fmt(%9.2f) star) se(par fmt(%9.2f))) style(tex) ///
stats(n SE FE Proposals, labels("N" "Clustering" "FE" "Proposals") ///
fmt(%9.0f %9.0f %9.0f %9.0f)) ///
starlevels(* .05 ** .01 *** .001) ///
keep(Gender CRT_dich PolAttIndex) /// 
order(Gender CRT_dich PolAttIndex) /// 
varlabels (Gender "Female" CRT_dich "High CRT Score" PolAttIndex "Political Attitudes Index \\ (Right $\rightarrow$ Left)") ///
mlabels(none) collabels(none)	
 
***************************************************************************************************
***************************************************************************************************
********Figure 2: Equality and Exclusionary Alliances by Gender, CRT, and Political Attitudes******
***************************************************************************************************
***************************************************************************************************

*First, collect the averages, by gender, for the pooled sample (all countries)* 
preserve
keep if proposer==1 & Gender!=.
collapse (mean) equality MWC, by(Gender)
gen iso3E=0

tempfile GenderOvr
save `GenderOvr'
restore

*Do the same for CRT* 
preserve
keep if proposer==1 & CRT_dich!=.

collapse (mean) equality MWC, by(CRT_dich)
gen iso3E=0

tempfile CRTOvr
save `CRTOvr'
restore

*Do the same for Political Attitudes* 
preserve
keep if proposer==1 & Above_Median!=.
collapse (mean) equality MWC, by(Above_Median)
gen iso3E=0

tempfile PolAttOvr
save `PolAttOvr'
restore

*Then, append to a country-level dataset, and create figure for each characteristic*

****************First, for Equality (panel A)***********

*Gender*
preserve
keep if proposer==1 & Gender!=.
collapse (mean) equality, by(iso3E Gender)
append using `GenderOvr'
drop MWC

label def iso3E3 0 "Pooled" 1 "AUS" 2 "AUT" 3 "CHN" 4 "COL" 5 "DEU" 6 "DNK" 7 "EGY" 8 "ESP" 9 "GBR" 10 "GTM" 11 "JPN" 12 "KEN" 13 "URY" 14 "USA"
label values iso3E iso3E3

reshape wide equality, i(iso3E) j(Gender)

ren equality0 yM
ren equality1 yF

scatter yF yM iso3E  || rspike yF yM iso3E, lc(black) legend(order(1 "Women" 2 "Men") pos(1) col(1) size(small)) xla(1/15) ///
 ylabel(75(5)95) ///
 xtitle("") title("a) Average Proposal Equality", size(medium)) subtitle(" ") ///
 xlabel(0(1)14, labsize(small) angle(vertical) valuelabel) ///
 xsize(2) ysize(1) 
  graph save "GenderGini.gph", replace
restore

*CRT*
preserve

keep if proposer==1 & CRT_dich!=.
collapse (mean) equality, by(iso3E CRT_dich)
append using `CRTOvr'
drop MWC

label def iso3E3 0 "Pooled" 1 "AUS" 2 "AUT" 3 "CHN" 4 "COL" 5 "DEU" 6 "DNK" 7 "EGY" 8 "ESP" 9 "GBR" 10 "GTM" 11 "JPN" 12 "KEN" 13 "URY" 14 "USA"
label values iso3E iso3E3

reshape wide equality, i(iso3E) j(CRT_dich)

ren equality0 yL
ren equality1 yH

scatter yL yH iso3E  || rspike yL yH iso3E, lc(black) legend(order(1 "Low CRT" 2 "High CRT") pos(1) col(1) size(small)) xla(1/15) ///
 ylabel(75(5)95) ///
 xtitle("") ///
 xlabel(0(1)14, labsize(small) angle(vertical) valuelabel) ///
 xsize(2) ysize(1) 
  graph save "CRTGini.gph", replace
restore 

*Political Attitudes*
preserve

keep if proposer==1 & Above_Median!=.
collapse (mean) equality, by(iso3E Above_Median)
append using `PolAttOvr'
drop MWC

label def iso3E3 0 "Pooled" 1 "AUS" 2 "AUT" 3 "CHN" 4 "COL" 5 "DEU" 6 "DNK" 7 "EGY" 8 "ESP" 9 "GBR" 10 "GTM" 11 "JPN" 12 "KEN" 13 "URY" 14 "USA"
label values iso3E iso3E3

reshape wide equality, i(iso3E) j(Above_Median)

ren equality0 yL
ren equality1 yH

scatter yH yL iso3E  || rspike yH yL iso3E, lc(black) legend(order(1 "Left-Leaning" 2 "Right-Leaning") pos(1) col(1) size(small)) xla(1/15) ///
 ylabel(75(5)95) ///
 xtitle("") ///
 xlabel(0(1)14, labsize(small) angle(vertical) valuelabel) ///
 xsize(2) ysize(1) 
  graph save "PolGini.gph", replace
restore

****************Second, for MWC (panel B)***********

*Gender*
preserve
keep if proposer==1 & Gender!=.
collapse (mean) MWC, by(iso3E Gender)
append using `GenderOvr'
drop equality

label def iso3E3 0 "Pooled" 1 "AUS" 2 "AUT" 3 "CHN" 4 "COL" 5 "DEU" 6 "DNK" 7 "EGY" 8 "ESP" 9 "GBR" 10 "GTM" 11 "JPN" 12 "KEN" 13 "URY" 14 "USA"
label values iso3E iso3E3

reshape wide MWC, i(iso3E) j(Gender)

ren MWC0 yM
ren MWC1 yF

scatter yF yM iso3E  || rspike yF yM iso3E, lc(black) legend(order(1 "Women" 2 "Men") pos(1) col(1) size(small)) xla(1/15) ///
 ylabel(.1(.2).7) ///
 xtitle("") title("b) Fraction of Exclusionary Alliances Proposed", size(medium)) subtitle(" ") ///
 xlabel(0(1)14, labsize(small) angle(vertical) valuelabel) ///
 xsize(2) ysize(1) 
  graph save "GenderMWC.gph", replace
restore

*CRT*
preserve
keep if proposer==1 & CRT_dich!=.
collapse (mean) MWC, by(iso3E CRT_dich)
append using `CRTOvr'
drop equality

label def iso3E3 0 "Pooled" 1 "AUS" 2 "AUT" 3 "CHN" 4 "COL" 5 "DEU" 6 "DNK" 7 "EGY" 8 "ESP" 9 "GBR" 10 "GTM" 11 "JPN" 12 "KEN" 13 "URY" 14 "USA"
label values iso3E iso3E3

reshape wide MWC, i(iso3E) j(CRT_dich)

ren MWC0 yL
ren MWC1 yH

scatter yL yH iso3E  || rspike yL yH iso3E, lc(black) legend(order(1 "Low CRT" 2 "High CRT") pos(1) col(1) size(small)) xla(1/15) ///
 ylabel(.1(.2).7) ///
 xtitle("") ///
 xlabel(0(1)14, labsize(small) angle(vertical) valuelabel) ///
 xsize(2) ysize(1) 
  graph save "CRTMWC.gph", replace
restore
 
*Political Attitudes*
preserve

keep if proposer==1 & Above_Median!=.
collapse (mean) MWC, by(iso3E Above_Median)
append using `PolAttOvr'
drop equality

label def iso3E3 0 "Pooled" 1 "AUS" 2 "AUT" 3 "CHN" 4 "COL" 5 "DEU" 6 "DNK" 7 "EGY" 8 "ESP" 9 "GBR" 10 "GTM" 11 "JPN" 12 "KEN" 13 "URY" 14 "USA"
label values iso3E iso3E3

reshape wide MWC, i(iso3E) j(Above_Median)

ren MWC0 yL
ren MWC1 yH

scatter yH yL iso3E  || rspike yH yL iso3E, lc(black) legend(order(1 "Left-Leaning" 2 "Right-Leaning") pos(1) col(1) size(small)) xla(1/15) ///
 ylabel(.1(.2).7) ///
 xtitle("") ///
 xlabel(0(1)14, labsize(small) angle(vertical) valuelabel) ///
 xsize(2) ysize(1) 
  graph save "PolMWC.gph", replace
restore
 
*Finally, combine graphs and adjust*
grc1leg "GenderGini.gph" "GenderMWC.gph", legendfrom("GenderMWC.gph") ring(0) pos(11.5) 
gr_edit .legend.plotregion1.DragBy -5.848988639512275 -16.155223053477404
graph export "Fig2_toppanel.pdf", as(pdf) replace
grc1leg "CRTGini.gph" "CRTMWC.gph", legendfrom("CRTMWC.gph") ring(0) pos(1) 
gr_edit .legend.DragBy 1.523967858132494 -85.50568024383483
graph export "Fig2_middlepanel.pdf", as(pdf) replace
grc1leg "PolGini.gph" "PolMWC.gph", legendfrom("PolMWC.gph") ring(0) pos(1) 
gr_edit .legend.DragBy 1.523967858132494 -79.50568024383483
graph export "Fig2_bottompanel.pdf", as(pdf) replace
  
***************************************************************************************************
***************************************************************************************************
**********************************Figure 4: Effects by Period Range********************************
***************************************************************************************************
***************************************************************************************************
 
*Panel A: Equality*
preserve
keep if proposer==1

capture drop temp
est clear
local i=0
forvalues bw = 3(3)15 {
foreach x in Gender Above_Median CRT_dich {
	local ++i
	di `i'
	gen t`i' = `x'
	areg equality t`i' Gender Above_Median CRT_dich if period<=`bw' & period>(`bw' - 3), cl(UniqueID) absorb(Country)
	estimates store est`i'
	drop t`i' 
  }	
} 

capture drop temp
gen temp = " " in 1
replace temp =  " " in 2
replace temp =  " " in 3
replace temp =  " " in 4
replace temp = " " in 5
replace temp = " " in 6
replace temp = " " in 7
replace temp = " " in 8
replace temp = " " in 9
replace temp = " " in 10
replace temp = " " in 11
replace temp = " " in 12
replace temp = " " in 13
replace temp = " " in 14
replace temp = " " in 15

coefplot est1 est2 est3 est4 est5 est6 est7 ///
	est8 est9 est10 est11 est12 est13 ///
	est14 est15, level(95 90) ///
keep(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15) yline(0, lcolor(gs14) lwidth(thin) lpattern(dash)) ///
scheme(s1color) aspectratio(0.5) xlab(0 " " 2 "1-3" 6 "4-6" 10 "7-9" 14 "10-12" 18 "13-15" 20 " ") ///
 groups(t1 t2 t3 = " " t4 t5 t6 = " " t7 t8 t9 = " " ///
  t10 t11 t12 = " " t13 t14 t15 = " ", labsize(tiny)) ///
 vertical  plotregion(lcolor(white))  xscale(lcolor(white)) yscale(lcolor(white)) ///
 coeflabel(t1=" " t2=" " t3=" " t4=" " t5=" " t6=" " t7=" " t8=" " t9=" " t10=" " t11=" " t12=" " ///
 t13=" " t14=" " t15=" ", notick) legend(order(2 "Female" 5 "Left-Leaning" 8 "High CRT") size(vsmall) rows(1)) ///
 p1(mcolor(navy%40)  ciopts(lcolor(navy%40 navy%40))) ///
 p2(mcolor(emerald%40) ciopts(lcolor(emerald%40 emerald%40))) ///
 p3(mcolor(lavender%40)  ciopts(lcolor(lavender%40 lavender%40))) ///
 p4(mcolor(navy%40)  ciopts(lcolor(navy%40 navy%40))) ///
 p5(mcolor(emerald%40) ciopts(lcolor(emerald%40 emerald%40))) ///
 p6(mcolor(lavender%40)  ciopts(lcolor(lavender%40 lavender%40))) ///
 p7(mcolor(navy%40)  ciopts(lcolor(navy%40 navy%40))) ///
 p8(mcolor(emerald%40) ciopts(lcolor(emerald%40 emerald%40))) ///
 p9(mcolor(lavender%40)  ciopts(lcolor(lavender%40 lavender%40))) ///
 p10(mcolor(navy%40)  ciopts(lcolor(navy%40 navy%40))) ///
 p11(mcolor(emerald%40) ciopts(lcolor(emerald%40 emerald%40))) ///
 p12(mcolor(lavender%40)  ciopts(lcolor(lavender%40 lavender%40))) ///
 p13(mcolor(navy%40)  ciopts(lcolor(navy%40 navy%40))) ///
 p14(mcolor(emerald%40) ciopts(lcolor(emerald%40 emerald%40))) ///
 p15(mcolor(lavender%40)  ciopts(lcolor(lavender%40 lavender%40))) ///
 grid() ytitle(" ") ///
 mlabel(temp) mlabsize(tiny) mlabcolor(gs5) mlabangle(vertical) mlabposition(4) ///
 subtitle("a) Equality") xtitle(" ")
  graph save "Fig4_PanelA.gph", replace
 drop temp
restore 
 
*Panel B: MWC*
preserve
keep if proposer==1

capture drop temp
est clear
local i=0
forvalues bw = 3(3)15 {
foreach x in Gender Above_Median CRT_dich {
	local ++i
	di `i'
	gen t`i' = `x'
	areg MWC t`i' Gender Above_Median CRT_dich if period<=`bw' & period>(`bw' - 3), cl(UniqueID) absorb(Country)
	estimates store est`i'
	drop t`i' 
  }	
} 

capture drop temp
gen temp = " " in 1
replace temp =  " " in 2
replace temp =  " " in 3
replace temp =  " " in 4
replace temp = " " in 5
replace temp = " " in 6
replace temp = " " in 7
replace temp = " " in 8
replace temp = " " in 9
replace temp = " " in 10
replace temp = " " in 11
replace temp = " " in 12
replace temp = " " in 13
replace temp = " " in 14
replace temp = " " in 15

coefplot est1 est2 est3 est4 est5 est6 est7 ///
	est8 est9 est10 est11 est12 est13 ///
	est14 est15, level(95 90) ///
keep(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15) yline(0, lcolor(gs14) lwidth(thin) lpattern(dash)) ///
scheme(s1color) aspectratio(0.5) xlab(0 " " 2 "1-3" 6 "4-6" 10 "7-9" 14 "10-12" 18 "13-15" 20 " ") ///
 groups(t1 t2 t3 = " " t4 t5 t6 = " " t7 t8 t9 = " " ///
  t10 t11 t12 = " " t13 t14 t15 = " ", labsize(tiny)) ///
 vertical  plotregion(lcolor(white))  xscale(lcolor(white)) yscale(lcolor(white)) ///
 coeflabel(t1=" " t2=" " t3=" " t4=" " t5=" " t6=" " t7=" " t8=" " t9=" " t10=" " t11=" " t12=" " ///
 t13=" " t14=" " t15=" ", notick) legend(order(2 "Female" 5 "Left-Leaning" 8 "High CRT") size(vsmall) rows(1)) ///
 p1(mcolor(navy%40)  ciopts(lcolor(navy%40 navy%40))) ///
 p2(mcolor(emerald%40) ciopts(lcolor(emerald%40 emerald%40))) ///
 p3(mcolor(lavender%40)  ciopts(lcolor(lavender%40 lavender%40))) ///
 p4(mcolor(navy%40)  ciopts(lcolor(navy%40 navy%40))) ///
 p5(mcolor(emerald%40) ciopts(lcolor(emerald%40 emerald%40))) ///
 p6(mcolor(lavender%40)  ciopts(lcolor(lavender%40 lavender%40))) ///
 p7(mcolor(navy%40)  ciopts(lcolor(navy%40 navy%40))) ///
 p8(mcolor(emerald%40) ciopts(lcolor(emerald%40 emerald%40))) ///
 p9(mcolor(lavender%40)  ciopts(lcolor(lavender%40 lavender%40))) ///
 p10(mcolor(navy%40)  ciopts(lcolor(navy%40 navy%40))) ///
 p11(mcolor(emerald%40) ciopts(lcolor(emerald%40 emerald%40))) ///
 p12(mcolor(lavender%40)  ciopts(lcolor(lavender%40 lavender%40))) ///
 p13(mcolor(navy%40)  ciopts(lcolor(navy%40 navy%40))) ///
 p14(mcolor(emerald%40) ciopts(lcolor(emerald%40 emerald%40))) ///
 p15(mcolor(lavender%40)  ciopts(lcolor(lavender%40 lavender%40))) ///
 grid() ytitle(" ") ///
 mlabel(temp) mlabsize(tiny) mlabcolor(gs5) mlabangle(vertical) mlabposition(4) ///
 subtitle("b) Exclusionary Alliances") xtitle(" ")
  graph save "Fig4_PanelB.gph", replace
 drop temp
restore 
  
*Combine and edit appearance*
grc1leg "Fig4_PanelA.gph" "Fig4_PanelB.gph", legendfrom("Fig4_PanelB.gph")  scheme(s1color) imargin(-3 -3 -4 -4) b1title("Period Range",size(small)) l1title("Point Estimate",size(small)) ring(1) 
gr_edit .b1title.DragBy 22.19671041868905 .1441344832382237
gr_edit .legend.DragBy 22.91738283488026 .4324034497147181
graph export "Fig4.pdf", as(pdf) replace
